package com.schoolComments.controller;


import com.schoolComments.dto.Result;
import com.schoolComments.entity.Blog;
import com.schoolComments.service.IBlogService;
import com.schoolComments.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private IBlogService blogService;
    @Resource
    private IUserService userService;

    @PostMapping
    public Result saveBlog(@RequestBody Blog blog) {
        return blogService.saveBlog(blog);
    }

    @GetMapping("/of/me")
    public Result queryMyBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryMyBlog(current);
    }

    @GetMapping("/hot")
    public Result queryHotBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryHotBlog(current);
    }

    //查看探店笔记
    @GetMapping("/{id}")
    public Result queryBlogByBlogId(@PathVariable Long id){
        return blogService.queryBlogByBlogId(id);
    }

    //博客点赞功能
    @PutMapping("/like/{id}")
    public Result likeBlog(@PathVariable("id") Long id) {
        return blogService.likeBlog(id);
    }

    //显示博客点赞的用户们
    @GetMapping("/likes/{id}")
    public Result queryBlogLikes(@PathVariable Long id){
        return blogService.queryBlogLikes(id);
    }

    //根据id查询当前博主的所有探店笔记
    @GetMapping("/of/user")
    public Result queryBlogsById(@RequestParam Long id, @RequestParam(value = "current", defaultValue = "1") Integer current){
        return blogService.queryBlogsById(id, current);
    }

    //滚动分页查询关注者发的动态
    @GetMapping("/of/follow")
    public Result queryblogOfFollow(@RequestParam("lastId") Long lastId, @RequestParam(value = "offset", defaultValue = "0") Integer offset){
        return blogService.queryblogOfFollow(lastId, offset);
    }


}
